import { observable, action } from 'mobx';
import {WeaForm} from 'comsMobx'
import {WeaLocaleProvider} from "ecCom"
import {Modal,message} from "antd"
import { toJS } from 'mobx';
import * as Apis from '../../apis/prjPortal';
const getLabel = WeaLocaleProvider.getLabel;

export class TaskGroupStore{
    @observable title = "";//编辑工作类型
    @observable form = new WeaForm();
	
	@observable formtype = "";
	@observable visible = false;
	@observable isright = true;
    @observable fieldinfo = [];
    @observable id = "";
    @observable rightMenu = "";
      
    validateRules = {};  //校验规则


    @action 
    handleTaskGroupDialog = (bool,params={id:''}) =>{
        this.visible = bool;
        if(bool){
            if(params.id!=''){
                this.id = params.id;
            }
            this.getTaskGroupForm(params);
        }
    }

    //初始化form
    getTaskGroupForm=(params={})=>{
        this.form = new WeaForm();
        Apis.getTaskGroupForm(params).then(data=>{
            this.fieldinfo = data.fieldinfo;
            this.rightMenu = data.rightMenus;
            if(this.id&&this.id!=""){
                this.title = getLabel('518193','编辑任务分组');
            }else{
                this.title = getLabel('518194','新建任务分组');
            }
            this.form && !this.form.isFormInit && this.form.initFormFields(data.fieldinfo);
        })
    }
	
	//项目分组保存
	saveTaskGroupInfo=(taskPortalStore,params={})=>{
		this.form.validateForm().then(f=>{
            if(f.isValid){
				let newParams = {...toJS(this.form.getFormParams()),...params,id:this.id,operation:'save'};
				Apis.doTaskGroupOperation(newParams).then(data=>{
                    if(data.success){
                        this.handleTaskGroupDialog(false);
                        taskPortalStore&&taskPortalStore.doSearch();
                        message.success(getLabel(18758,"保存成功"));
                    }else{
                        message.error(getLabel('507580','出现错误！对不起，您暂时没有权限！！'));
                    }
				})
            }else{
                f.showErrors();
            }
        });
	}

    //更新数据
    setFormFields=(value)=>{
        this.form.updateFields(value, false);   
    }

    setId = (v) =>{
        this.id = v;
    }

}
